
/*
 * IUsuario.java
 *
 * Created on 28/01/2013, 02:24:27 PM
 */
package elaprendiz.ventanas;

import elaprendiz.config.AppConfig;
import elaprendiz.controllers.CUsuario;
import elaprendiz.core.DatoArchivo;
import elaprendiz.modelbd.Usuario;
import elaprendiz.util.ECampos;
import elaprendiz.util.FiltraEntrada;
import elaprendiz.util.Helper;
import elaprendiz.util.Thumbnail;
import elaprendiz.util.VerificadorEntrada;
import elaprendiz.util.filechooser.FiltraExtensionArchivos;
import elaprendiz.util.filechooser.PanelVistaPrevia;
import elaprendiz.util.filechooser.VistaArchivos;
import elaprendiz.ventanas.buscar.BuscarUsuario;
import elaprendiz.ventanas.paneles.CambiarPassword;
import elaprendiz.ventanas.paneles.EncargadoAlmacenPanel;
import elaprendiz.ventanas.paneles.PanelBitacora;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Image;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeModel;

/**
 *
 * @author Ferz elaprendiz - www.elaprendiz.net63.net
 */
public class IUsuario extends javax.swing.JInternalFrame {

    /** Creates new form IUsuario */
    private FileInputStream imagen;
    private Calendar fecha = Calendar.getInstance();
    private DatoArchivo dat;
    private int contadorPag = 0;
    private int numRegitros = 0;
    private CUsuario cUser;
    private Usuario usuario;
    private boolean esActualizacion = false;
    public IUsuario() {
        initComponents();
        pnlOpcional.setVisible(false);
        this.setSize(new Dimension(this.getWidth(),450));
        cUser = new CUsuario();
        setFiltro();
        this.txtDni.requestFocus();
        cUser.setNumPaginador(contadorPag, 1);
        usuario = cUser.getRegistro();
        setUsuario(usuario);
        numRegitros = cUser.getNumeroRegistros();
        if(!AppConfig.getUsuario().verificarAcceso("buscarProducto"))
        {
            this.bntNuevo.setEnabled(false);
            this.bntNuevo.setVisible(false);
        }
        DefaultMutableTreeNode permisos = usuario.getPermisos();
        tPermisos.setModel(new javax.swing.tree.DefaultTreeModel(permisos));        
        tPermisos.setShowsRootHandles(true);
        tPermisos.expandRow(0);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        panelImage1 = new elaprendiz.gui.panel.PanelImage();
        pnlPaginador = new javax.swing.JPanel();
        bntPrimero = new elaprendiz.gui.button.ButtonRect();
        bntAnterior = new elaprendiz.gui.button.ButtonRect();
        bntBuscar = new elaprendiz.gui.button.ButtonRect();
        bntSiguiente = new elaprendiz.gui.button.ButtonRect();
        bntUltimo = new elaprendiz.gui.button.ButtonRect();
        jPanel1 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        pnlCmpObligatorios = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtDni = new elaprendiz.gui.textField.TextFieldRectBackground();
        txtCodigo = new elaprendiz.gui.textField.TextFieldRectBackground();
        txtLogn = new elaprendiz.gui.textField.TextFieldRectBackground();
        txtNombre = new elaprendiz.gui.textField.TextFieldRectBackground();
        txtApellidos = new elaprendiz.gui.textField.TextFieldRectBackground();
        txtPassword = new elaprendiz.gui.passwordField.PasswordFieldRectBackground();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        txtFono = new elaprendiz.gui.textField.TextFieldRectBackground();
        cbSexo = new elaprendiz.gui.comboBox.ComboBoxRect();
        cbTipoCargo = new elaprendiz.gui.comboBox.ComboBoxRect();
        jLabel10 = new javax.swing.JLabel();
        dcFechaRegistro = new com.toedter.calendar.JDateChooser();
        pnlFoto = new javax.swing.JPanel();
        pnlImagen = new elaprendiz.gui.panel.PanelImage();
        tbntOpcional = new javax.swing.JToggleButton();
        bntActivar = new javax.swing.JButton();
        bntBitacora = new elaprendiz.gui.button.ButtonRect();
        pnlOpcional = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        dcFechaNacimiento = new com.toedter.calendar.JDateChooser();
        txtFono2 = new elaprendiz.gui.textField.TextField();
        txtCelular = new elaprendiz.gui.textField.TextField();
        txtNextel = new elaprendiz.gui.textField.TextField();
        txtEmail = new elaprendiz.gui.textField.TextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtADescripcion = new javax.swing.JTextArea();
        jPanel4 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tPermisos = new javax.swing.JTree();
        pnlBotones = new javax.swing.JPanel();
        bntNuevo = new elaprendiz.gui.button.ButtonRect();
        bntModificar = new elaprendiz.gui.button.ButtonRect();
        bntPass = new elaprendiz.gui.button.ButtonRect();
        bntGrabar = new elaprendiz.gui.button.ButtonRect();
        bntEliminar = new elaprendiz.gui.button.ButtonRect();
        bntCancelar = new elaprendiz.gui.button.ButtonRect();
        bntSalir = new elaprendiz.gui.button.ButtonRect();

        setClosable(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setIconifiable(true);
        setTitle("Formulario Usuario");
        setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/elaprendiz/resources/user_blue_32.png"))); // NOI18N
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameClosing(evt);
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
        });

        panelImage1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/elaprendiz/resources/fondoazulceleste.jpg"))); // NOI18N
        panelImage1.setLayout(new javax.swing.BoxLayout(panelImage1, javax.swing.BoxLayout.PAGE_AXIS));

        pnlPaginador.setOpaque(false);

        bntPrimero.setBackground(new java.awt.Color(102, 204, 0));
        bntPrimero.setText("<<");
        bntPrimero.setEnabled(false);
        bntPrimero.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntPrimeroActionPerformed(evt);
            }
        });
        pnlPaginador.add(bntPrimero);

        bntAnterior.setBackground(new java.awt.Color(102, 204, 0));
        bntAnterior.setText("<");
        bntAnterior.setEnabled(false);
        bntAnterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntAnteriorActionPerformed(evt);
            }
        });
        pnlPaginador.add(bntAnterior);

        bntBuscar.setBackground(new java.awt.Color(102, 204, 0));
        bntBuscar.setText("Buscar");
        bntBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntBuscarActionPerformed(evt);
            }
        });
        pnlPaginador.add(bntBuscar);

        bntSiguiente.setBackground(new java.awt.Color(102, 204, 0));
        bntSiguiente.setText(">");
        bntSiguiente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntSiguienteActionPerformed(evt);
            }
        });
        pnlPaginador.add(bntSiguiente);

        bntUltimo.setBackground(new java.awt.Color(102, 204, 0));
        bntUltimo.setText(">>");
        bntUltimo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntUltimoActionPerformed(evt);
            }
        });
        pnlPaginador.add(bntUltimo);

        panelImage1.add(pnlPaginador);

        jPanel1.setOpaque(false);
        jPanel1.setLayout(new javax.swing.BoxLayout(jPanel1, javax.swing.BoxLayout.LINE_AXIS));

        jPanel3.setOpaque(false);
        jPanel3.setPreferredSize(new java.awt.Dimension(666, 563));
        jPanel3.setLayout(new javax.swing.BoxLayout(jPanel3, javax.swing.BoxLayout.PAGE_AXIS));

        pnlCmpObligatorios.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos Obligatorios", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11), new java.awt.Color(0, 0, 0))); // NOI18N
        pnlCmpObligatorios.setOpaque(false);
        pnlCmpObligatorios.setLayout(new java.awt.GridBagLayout());

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel1.setText("DNI:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 1, 3);
        pnlCmpObligatorios.add(jLabel1, gridBagConstraints);

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel2.setText("Codigo:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 1, 3);
        pnlCmpObligatorios.add(jLabel2, gridBagConstraints);

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel3.setText("Login:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 1, 3);
        pnlCmpObligatorios.add(jLabel3, gridBagConstraints);

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel4.setText("Nombre:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 1, 3);
        pnlCmpObligatorios.add(jLabel4, gridBagConstraints);

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel5.setText("Apellidos:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 1, 3);
        pnlCmpObligatorios.add(jLabel5, gridBagConstraints);

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel6.setText("Contraseña:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 1, 3);
        pnlCmpObligatorios.add(jLabel6, gridBagConstraints);

        txtDni.setEditable(false);
        txtDni.setDescripcion("Obligatorio");
        txtDni.setName("tdni"); // NOI18N
        txtDni.setPreferredSize(new java.awt.Dimension(120, 26));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 1, 3);
        pnlCmpObligatorios.add(txtDni, gridBagConstraints);

        txtCodigo.setEditable(false);
        txtCodigo.setDescripcion("Obligatorio");
        txtCodigo.setName("tcod"); // NOI18N
        txtCodigo.setPreferredSize(new java.awt.Dimension(120, 26));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 1, 3);
        pnlCmpObligatorios.add(txtCodigo, gridBagConstraints);

        txtLogn.setEditable(false);
        txtLogn.setToolTipText("Nombre Para Ingresar al Sistema:");
        txtLogn.setDescripcion("Obligatorio");
        txtLogn.setName("tlog"); // NOI18N
        txtLogn.setPreferredSize(new java.awt.Dimension(120, 26));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 1, 3);
        pnlCmpObligatorios.add(txtLogn, gridBagConstraints);

        txtNombre.setEditable(false);
        txtNombre.setDescripcion("Obligatorio");
        txtNombre.setName("tnom"); // NOI18N
        txtNombre.setPreferredSize(new java.awt.Dimension(325, 26));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 8;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 1, 3);
        pnlCmpObligatorios.add(txtNombre, gridBagConstraints);

        txtApellidos.setEditable(false);
        txtApellidos.setDescripcion("Obligatorio");
        txtApellidos.setName("tape"); // NOI18N
        txtApellidos.setPreferredSize(new java.awt.Dimension(325, 26));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 8;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 1, 3);
        pnlCmpObligatorios.add(txtApellidos, gridBagConstraints);

        txtPassword.setEditable(false);
        txtPassword.setDescripcion("Obligatorio");
        txtPassword.setName("tpass"); // NOI18N
        txtPassword.setPreferredSize(new java.awt.Dimension(325, 26));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = 8;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 1, 3);
        pnlCmpObligatorios.add(txtPassword, gridBagConstraints);

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel7.setText("Telefono:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 1, 3);
        pnlCmpObligatorios.add(jLabel7, gridBagConstraints);

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel8.setText("Sexo:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 1, 3);
        pnlCmpObligatorios.add(jLabel8, gridBagConstraints);

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel9.setText("Tipo Cargo:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 1, 3);
        pnlCmpObligatorios.add(jLabel9, gridBagConstraints);

        txtFono.setEditable(false);
        txtFono.setDescripcion("Obligatorio");
        txtFono.setName("tfono"); // NOI18N
        txtFono.setPreferredSize(new java.awt.Dimension(150, 26));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 1, 3);
        pnlCmpObligatorios.add(txtFono, gridBagConstraints);

        cbSexo.setModel(new DefaultComboBoxModel(Usuario.sexos));
        cbSexo.setEnabled(false);
        cbSexo.setName("cbsexo"); // NOI18N
        cbSexo.setPreferredSize(new java.awt.Dimension(120, 26));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 1, 3);
        pnlCmpObligatorios.add(cbSexo, gridBagConstraints);

        cbTipoCargo.setModel(new DefaultComboBoxModel(Usuario.tCargos));
        cbTipoCargo.setEnabled(false);
        cbTipoCargo.setName("cbcargo"); // NOI18N
        cbTipoCargo.setPreferredSize(new java.awt.Dimension(150, 26));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 1, 3);
        pnlCmpObligatorios.add(cbTipoCargo, gridBagConstraints);

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel10.setText("Fecha de Registro:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 1, 3);
        pnlCmpObligatorios.add(jLabel10, gridBagConstraints);

        dcFechaRegistro.setEnabled(false);
        dcFechaRegistro.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        dcFechaRegistro.setPreferredSize(new java.awt.Dimension(150, 26));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 1, 3);
        pnlCmpObligatorios.add(dcFechaRegistro, gridBagConstraints);

        pnlFoto.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, new java.awt.Color(0, 0, 0), new java.awt.Color(0, 0, 0), null, new java.awt.Color(0, 0, 0)), "Foto", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12), new java.awt.Color(0, 0, 0))); // NOI18N
        pnlFoto.setToolTipText("Click Para cambiar de Imagen");
        pnlFoto.setEnabled(false);
        pnlFoto.setOpaque(false);
        pnlFoto.setPreferredSize(new java.awt.Dimension(140, 140));
        pnlFoto.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                pnlFotoMouseClicked(evt);
            }
        });
        pnlFoto.setLayout(new java.awt.BorderLayout());

        pnlImagen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/elaprendiz/resources/defaultlarge.gif"))); // NOI18N

        javax.swing.GroupLayout pnlImagenLayout = new javax.swing.GroupLayout(pnlImagen);
        pnlImagen.setLayout(pnlImagenLayout);
        pnlImagenLayout.setHorizontalGroup(
            pnlImagenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 128, Short.MAX_VALUE)
        );
        pnlImagenLayout.setVerticalGroup(
            pnlImagenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 117, Short.MAX_VALUE)
        );

        pnlFoto.add(pnlImagen, java.awt.BorderLayout.CENTER);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.gridheight = 6;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.PAGE_START;
        pnlCmpObligatorios.add(pnlFoto, gridBagConstraints);

        tbntOpcional.setText("Campos Opcionales");
        tbntOpcional.setPreferredSize(new java.awt.Dimension(170, 26));
        tbntOpcional.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tbntOpcionalActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 2, 0);
        pnlCmpObligatorios.add(tbntOpcional, gridBagConstraints);

        bntActivar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/elaprendiz/resources/user_business_close_32.png"))); // NOI18N
        bntActivar.setText("<html>\n<body>\nUsuario Eliminado <br/>\nClick para Activarlo\n</body>\n</html>");
        bntActivar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntActivarActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 9;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.gridheight = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.PAGE_START;
        pnlCmpObligatorios.add(bntActivar, gridBagConstraints);

        bntBitacora.setBackground(new java.awt.Color(51, 153, 255));
        bntBitacora.setText("Ver Bitacora");
        bntBitacora.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntBitacoraActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 9;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 4, 0);
        pnlCmpObligatorios.add(bntBitacora, gridBagConstraints);

        jPanel3.add(pnlCmpObligatorios);

        pnlOpcional.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos Opcionales", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11), new java.awt.Color(0, 0, 0))); // NOI18N
        pnlOpcional.setOpaque(false);
        pnlOpcional.setLayout(new java.awt.GridBagLayout());

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel11.setText("Fecha de Nacimiento:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 4);
        pnlOpcional.add(jLabel11, gridBagConstraints);

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel12.setText("Telefono Nro. 2:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 4);
        pnlOpcional.add(jLabel12, gridBagConstraints);

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel13.setText("Celular:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 4);
        pnlOpcional.add(jLabel13, gridBagConstraints);

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel14.setText("Nextel:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 4);
        pnlOpcional.add(jLabel14, gridBagConstraints);

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel15.setText("Email:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 4);
        pnlOpcional.add(jLabel15, gridBagConstraints);

        jLabel16.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel16.setText("Descripcion:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 4);
        pnlOpcional.add(jLabel16, gridBagConstraints);

        dcFechaNacimiento.setEnabled(false);
        dcFechaNacimiento.setPreferredSize(new java.awt.Dimension(150, 26));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 4);
        pnlOpcional.add(dcFechaNacimiento, gridBagConstraints);

        txtFono2.setEditable(false);
        txtFono2.setPreferredSize(new java.awt.Dimension(150, 26));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 4);
        pnlOpcional.add(txtFono2, gridBagConstraints);

        txtCelular.setEditable(false);
        txtCelular.setPreferredSize(new java.awt.Dimension(150, 26));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 4);
        pnlOpcional.add(txtCelular, gridBagConstraints);

        txtNextel.setEditable(false);
        txtNextel.setPreferredSize(new java.awt.Dimension(150, 26));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 4);
        pnlOpcional.add(txtNextel, gridBagConstraints);

        txtEmail.setEditable(false);
        txtEmail.setInputVerifier(new VerificadorEntrada(125,VerificadorEntrada.EMAIL));
        txtEmail.setPreferredSize(new java.awt.Dimension(150, 26));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 4);
        pnlOpcional.add(txtEmail, gridBagConstraints);

        jScrollPane1.setPreferredSize(new java.awt.Dimension(420, 50));

        txtADescripcion.setColumns(20);
        txtADescripcion.setEditable(false);
        txtADescripcion.setLineWrap(true);
        txtADescripcion.setRows(5);
        txtADescripcion.setPreferredSize(new java.awt.Dimension(300, 30));
        jScrollPane1.setViewportView(txtADescripcion);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.gridheight = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 7, 4);
        pnlOpcional.add(jScrollPane1, gridBagConstraints);

        jPanel3.add(pnlOpcional);

        jPanel1.add(jPanel3);

        jPanel4.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel4.setOpaque(false);
        jPanel4.setLayout(new java.awt.BorderLayout());

        jPanel6.setOpaque(false);
        jPanel6.setLayout(new java.awt.BorderLayout());

        jScrollPane2.setPreferredSize(new java.awt.Dimension(200, 322));

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("JTree");
        javax.swing.tree.DefaultMutableTreeNode treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("colors");
        javax.swing.tree.DefaultMutableTreeNode treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("blue");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("violet");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("red");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("yellow");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("sports");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("basketball");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("soccer");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("football");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("food");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("hot dogs");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("pizza");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("ravioli");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("bananas");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        tPermisos.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        tPermisos.setShowsRootHandles(true);
        jScrollPane2.setViewportView(tPermisos);

        jPanel6.add(jScrollPane2, java.awt.BorderLayout.CENTER);

        jPanel4.add(jPanel6, java.awt.BorderLayout.CENTER);

        jPanel1.add(jPanel4);

        panelImage1.add(jPanel1);

        pnlBotones.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        pnlBotones.setOpaque(false);
        pnlBotones.setPreferredSize(new java.awt.Dimension(475, 38));

        bntNuevo.setBackground(new java.awt.Color(51, 153, 255));
        bntNuevo.setText("Nuevo");
        bntNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntNuevoActionPerformed(evt);
            }
        });
        pnlBotones.add(bntNuevo);

        bntModificar.setBackground(new java.awt.Color(51, 153, 255));
        bntModificar.setText("Modificar");
        bntModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntModificarActionPerformed(evt);
            }
        });
        pnlBotones.add(bntModificar);

        bntPass.setBackground(new java.awt.Color(51, 153, 255));
        bntPass.setText("Cambiar Contraseña");
        bntPass.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntPassActionPerformed(evt);
            }
        });
        pnlBotones.add(bntPass);

        bntGrabar.setBackground(new java.awt.Color(51, 153, 255));
        bntGrabar.setText("Grabar");
        bntGrabar.setEnabled(false);
        bntGrabar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntGrabarActionPerformed(evt);
            }
        });
        pnlBotones.add(bntGrabar);

        bntEliminar.setBackground(new java.awt.Color(51, 153, 255));
        bntEliminar.setText("Eliminar");
        bntEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntEliminarActionPerformed(evt);
            }
        });
        pnlBotones.add(bntEliminar);

        bntCancelar.setBackground(new java.awt.Color(51, 153, 255));
        bntCancelar.setText("Cancelar");
        bntCancelar.setEnabled(false);
        bntCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntCancelarActionPerformed(evt);
            }
        });
        pnlBotones.add(bntCancelar);

        bntSalir.setBackground(new java.awt.Color(51, 153, 255));
        bntSalir.setText("Salir");
        bntSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntSalirActionPerformed(evt);
            }
        });
        pnlBotones.add(bntSalir);

        panelImage1.add(pnlBotones);

        getContentPane().add(panelImage1, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void tbntOpcionalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tbntOpcionalActionPerformed
    mostrarCamposOpcionales(tbntOpcional.isSelected());
}//GEN-LAST:event_tbntOpcionalActionPerformed

private void pnlFotoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlFotoMouseClicked
    if(pnlFoto.isEnabled())
    {
        JFileChooser se = new JFileChooser();
        se.setFileSelectionMode(JFileChooser.FILES_ONLY);
        se.setMultiSelectionEnabled(false);
        se.setAccessory(new PanelVistaPrevia(se));
        se.setFileFilter(new FiltraExtensionArchivos());
        se.setFileView(new VistaArchivos());
        int estado = se.showOpenDialog(null);
        if(estado == JFileChooser.APPROVE_OPTION)
        {
            try {
                Thumbnail tn;
                imagen = new FileInputStream(se.getSelectedFile());
                Image icono = ImageIO.read(imagen).getScaledInstance(300, 200, Image.SCALE_AREA_AVERAGING);
                tn = new Thumbnail(icono,System.getProperty("user.dir")+"/"+se.getSelectedFile().getName());
                imagen = tn.generarThumbnail();
                this.pnlImagen.setIcon(new ImageIcon(System.getProperty("user.dir")+"/"+se.getSelectedFile().getName()));
                this.pnlImagen.updateUI();
                dat = new DatoArchivo(imagen,(int)se.getSelectedFile().length());
                    
            } catch (FileNotFoundException ex) {
                Logger.getLogger(IUsuario.class.getName()).log(Level.SEVERE, null, ex);
            }catch (IOException ex) {
                        Logger.getLogger(IUsuario.class.getName()).log(Level.SEVERE, null, ex);
                    }
        }
    }
}//GEN-LAST:event_pnlFotoMouseClicked

private void bntNuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntNuevoActionPerformed
    String ncod = Helper.generarCodigo(cUser.getCodigoUsuario(),"U");    
    ECampos.setEditableTexto(pnlCmpObligatorios, true, null, true, "");
    ECampos.setEditableTexto(this.pnlOpcional, true, null, true, "");
    ECampos.buscarBotones(pnlPaginador, false, null);
    this.dcFechaNacimiento.setEnabled(true);
    this.dcFechaRegistro.setEnabled(true);
    this.dcFechaRegistro.setDate(fecha.getTime());
    this.cbSexo.setSelectedIndex(0);
    this.cbTipoCargo.setSelectedIndex(0);
    this.cbSexo.setEnabled(true);
    this.cbTipoCargo.setEnabled(true);
    this.pnlFoto.setEnabled(true);
    ECampos.buscarBotones(pnlBotones, true, null);
    ECampos.buscarBotones(pnlBotones, false, new Component[]{this.bntCancelar,this.bntGrabar,this.bntSalir});
    this.txtCodigo.setText(ncod);
    dat = null;
    imagen = null;
    this.pnlImagen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/elaprendiz/resources/defaultlarge.gif")));
    this.bntActivar.setVisible(false);
    esActualizacion=false;
    bntBitacora.setVisible(false);
}//GEN-LAST:event_bntNuevoActionPerformed

private void bntCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntCancelarActionPerformed
   
    int nu = JOptionPane.showInternalConfirmDialog(this, "Al Cancelar esta operacion, se borraran\n"
            + "todo los datos Ingresados\n"
            + "¿Desea cancelar esta operacion?", "Cancelar Operacion", JOptionPane.YES_NO_CANCEL_OPTION);
    if(nu == JOptionPane.OK_OPTION)
    {
        ECampos.buscarBotones(pnlPaginador, true, null);
       ECampos.setEditableTexto(pnlCmpObligatorios, false, null, true, "");
        ECampos.setEditableTexto(this.pnlOpcional, false, null, true, "");
        this.dcFechaNacimiento.setEnabled(false);
        this.dcFechaRegistro.setEnabled(false);
        this.dcFechaRegistro.setDate(null);
        this.cbSexo.setSelectedIndex(0);
        this.cbTipoCargo.setSelectedIndex(0);
        this.cbSexo.setEnabled(false);
        this.cbTipoCargo.setEnabled(false);    
        this.pnlFoto.setEnabled(false);
        ECampos.buscarBotones(pnlBotones, false, null);
        ECampos.buscarBotones(pnlBotones, true, new Component[]{this.bntCancelar,this.bntGrabar});
        dat = null;
        imagen = null;
        this.pnlImagen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/elaprendiz/resources/defaultlarge.gif")));
        if(cUser.getRegistro() != null)
        {
          setUsuario(cUser.getRegistro());  
        }
        esActualizacion=false;  
        bntBitacora.setVisible(true);
    }
       
}//GEN-LAST:event_bntCancelarActionPerformed

private void bntModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntModificarActionPerformed
    ECampos.buscarBotones(pnlPaginador, false, null);
    ECampos.setEditableTexto(pnlCmpObligatorios, true, null, false, "");
    ECampos.setEditableTexto(this.pnlOpcional, true, null, false, "");
    this.dcFechaNacimiento.setEnabled(true);
    this.dcFechaRegistro.setEnabled(true);
    this.cbSexo.setEnabled(true);
    this.cbTipoCargo.setEnabled(true);
    this.pnlFoto.setEnabled(true);
    ECampos.buscarBotones(pnlBotones, true, null);
    ECampos.buscarBotones(pnlBotones, false, new Component[]{this.bntCancelar,this.bntGrabar,this.bntSalir});
    esActualizacion=true;
    bntBitacora.setVisible(false);
}//GEN-LAST:event_bntModificarActionPerformed

private void bntGrabarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntGrabarActionPerformed
    if(ECampos.esObligatorio(this.pnlCmpObligatorios,true))  
    {
       JOptionPane.showInternalMessageDialog(this, "Los campos Marcados "+
                   "son oligatorios", "No deje campos vacios", JOptionPane.ERROR_MESSAGE);
           return; 
    }
   if(!esActualizacion)
   {
     int nu = JOptionPane.showInternalConfirmDialog(this, "Desea Registrar nuevo Usuario", "Registrar usuario", JOptionPane.YES_NO_CANCEL_OPTION);
     if(nu == JOptionPane.OK_OPTION)
     {
       grabarRegistro();       
       asignarAlmacen(cUser.getUltimoUsuario());
       imagen = null;  
       reiniciarCampos();
     }
   }
   
   if(esActualizacion)
   {
       int nu = JOptionPane.showInternalConfirmDialog(this, "Desea Modificar Estos Datos", "Modificar Datos", JOptionPane.YES_NO_CANCEL_OPTION);
     if(nu == JOptionPane.OK_OPTION){
         int rs = 0;
      if(imagen != null)
      {
          rs = cUser.actualizarConFoto(this.capturarValoresCamposConFoto());
      }else{
          rs = cUser.actualizarRegistro(this.capturarValoresCamposSinFoto());
      }
      if(rs !=0)
      {
          JOptionPane.showInternalMessageDialog(this, "Registro actualizado", "Usuario modificado", JOptionPane.INFORMATION_MESSAGE);
      }
      esActualizacion=false; 
      reiniciarCampos();
     }
   }
   
}//GEN-LAST:event_bntGrabarActionPerformed

private void bntEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntEliminarActionPerformed
    if(usuario != null)
    {
        int nu = JOptionPane.showInternalConfirmDialog(this, "Desea Eliminar este Usuario", "Eliminar Usuario", JOptionPane.YES_NO_CANCEL_OPTION);
        if(nu == JOptionPane.OK_OPTION)
        {
           int br = cUser.borrarRegistro(usuario);
            if(br != 0)
            {

               bntEliminar.setEnabled(false); 
               this.bntActivar.setVisible(true);
               usuario.setActivo(0);
               JOptionPane.showInternalMessageDialog(this, "Usuario Eliminado", "Eliminacion Correcta", JOptionPane.INFORMATION_MESSAGE);
            } 
        }
        
    }
}//GEN-LAST:event_bntEliminarActionPerformed

private void bntSiguienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntSiguienteActionPerformed
    contadorPag++;
    if(contadorPag >= this.numRegitros)
    {
      contadorPag = this.numRegitros-1; 
      bntSiguiente.setEnabled(false);
      this.bntUltimo.setEnabled(false);
    }
    bntAnterior.setEnabled(true);
    this.bntPrimero.setEnabled(true);
    cUser.setNumPaginador(contadorPag, 1);
    usuario = cUser.getRegistro();
    setUsuario(usuario);
}//GEN-LAST:event_bntSiguienteActionPerformed

private void bntAnteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntAnteriorActionPerformed
    contadorPag--;
    if(contadorPag<0)
    {
      contadorPag = 0;
      bntAnterior.setEnabled(false);
      this.bntPrimero.setEnabled(false);
    }
    bntSiguiente.setEnabled(true);
    this.bntUltimo.setEnabled(true);
    cUser.setNumPaginador(contadorPag, 1);
    usuario = cUser.getRegistro();
    setUsuario(usuario);
}//GEN-LAST:event_bntAnteriorActionPerformed

private void bntPrimeroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntPrimeroActionPerformed
    contadorPag = 0;
    cUser.setNumPaginador(contadorPag, 1);
    usuario = cUser.getRegistro();
    setUsuario(usuario);
    bntSiguiente.setEnabled(true);
    this.bntUltimo.setEnabled(true);
    bntAnterior.setEnabled(false);
    this.bntPrimero.setEnabled(false);
}//GEN-LAST:event_bntPrimeroActionPerformed

private void bntUltimoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntUltimoActionPerformed
    contadorPag = this.numRegitros-1;
    cUser.setNumPaginador(contadorPag, 1);
    usuario = cUser.getRegistro();
    setUsuario(usuario);
     bntAnterior.setEnabled(true);
    this.bntPrimero.setEnabled(true);
    bntSiguiente.setEnabled(false);
    this.bntUltimo.setEnabled(false);
}//GEN-LAST:event_bntUltimoActionPerformed

private void bntBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntBuscarActionPerformed
BuscarUsuario pvc = new BuscarUsuario();
       JLabel aviso = pvc.getLbAviso();
       
        JOptionPane.showInternalOptionDialog(this, pvc, "Buscar Usuarios",JOptionPane.OK_CANCEL_OPTION,
                                            JOptionPane.QUESTION_MESSAGE, null, new Object[]{aviso},null);
   
        if(pvc.getSeleccionado() != null)
        {
           this.setUsuario(pvc.getSeleccionado());           
        }   
}//GEN-LAST:event_bntBuscarActionPerformed

private void bntActivarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntActivarActionPerformed
    if(usuario != null)
    {
        int nu = JOptionPane.showInternalConfirmDialog(this, "Desea Activar a este Usuario", "Activar usuario", JOptionPane.YES_NO_CANCEL_OPTION);
        if(nu == JOptionPane.OK_OPTION)
        {
           int br = cUser.activarUsuario(usuario);
            if(br != 0)
            {            
               bntEliminar.setEnabled(true); 
               this.bntActivar.setVisible(false);
               usuario.setActivo(1);
               JOptionPane.showInternalMessageDialog(this, "Usuario Activado", "Activacion Correcta", JOptionPane.INFORMATION_MESSAGE);
            } 
        }
        
    }
}//GEN-LAST:event_bntActivarActionPerformed

private void bntPassActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntPassActionPerformed
   if(usuario != null)
   {
       int nu = JOptionPane.showInternalConfirmDialog(this, "Desea cambiar la contraseña", "Cambiar Contraseña", JOptionPane.YES_NO_CANCEL_OPTION);
       if(nu == JOptionPane.OK_OPTION){
           CambiarPassword pvc = new CambiarPassword(usuario);
           JLabel aviso = pvc.getLbAviso();

            JOptionPane.showInternalOptionDialog(this, pvc, "Cambiar Contraseña",JOptionPane.OK_CANCEL_OPTION,
                                                JOptionPane.QUESTION_MESSAGE, null, new Object[]{aviso},null);

            if(pvc.getSeActualizo() == 1)
            {
                JOptionPane.showInternalMessageDialog(this, "Contraseña Cambiada correctamente", "Contraseña cambiada", JOptionPane.INFORMATION_MESSAGE);
               this.setUsuario(usuario);           
            }
       }
   }
    
}//GEN-LAST:event_bntPassActionPerformed

private void formInternalFrameClosing(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameClosing
    cerrarVentana();
}//GEN-LAST:event_formInternalFrameClosing

private void bntSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntSalirActionPerformed
    cerrarVentana();
}//GEN-LAST:event_bntSalirActionPerformed

private void bntBitacoraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntBitacoraActionPerformed
 if(usuario != null)
 {
   PanelBitacora pvc = new PanelBitacora(usuario);
   JLabel aviso = new JLabel("");
   aviso.setVisible(false);
    JOptionPane.showInternalOptionDialog(this, pvc, "Registro de Ingresos",JOptionPane.OK_CANCEL_OPTION,
                                        JOptionPane.QUESTION_MESSAGE, null, new Object[]{aviso},null);

 }
    
}//GEN-LAST:event_bntBitacoraActionPerformed

private void asignarAlmacen(Usuario user)
{
    EncargadoAlmacenPanel pvc = new EncargadoAlmacenPanel(user);
       JLabel aviso = new JLabel();
       aviso.setVisible(false);
       
        JOptionPane.showInternalOptionDialog(this, pvc, "Asignar Almacen",JOptionPane.OK_CANCEL_OPTION,
                                            JOptionPane.QUESTION_MESSAGE, null, new Object[]{aviso},null);
   
        if(pvc.EsAceptado())
        {
           pvc.guardar();          
        } 
}
private void cerrarVentana()
{
     int nu = JOptionPane.showInternalConfirmDialog(this, "Todos los datos que no se ha guardado "
         + "se perderan.\n"
         + "¿Desea Cerrar esta ventana?", "Cerrar ventana", JOptionPane.YES_NO_CANCEL_OPTION);
     if(nu == JOptionPane.OK_OPTION)
     {
         ECampos.buscarBotones(pnlPaginador, true, null);
        pnlOpcional.setVisible(false);
        this.setSize(new Dimension(this.getWidth(),450));
        cUser = new CUsuario();        
        this.txtDni.requestFocus();
        contadorPag = 0;
        cUser.setNumPaginador(contadorPag, 1);
        usuario = cUser.getRegistro();
        setUsuario(usuario);
        numRegitros = cUser.getNumeroRegistros();
        ECampos.buscarBotones(pnlBotones, false, null);
        ECampos.buscarBotones(pnlBotones, true, new Component[]{this.bntCancelar,this.bntGrabar});
        dat = null;
        imagen = null;
        esActualizacion=false;
        bntBitacora.setVisible(true);
        this.dispose();
     }
}
private void reiniciarCampos()
{
    ECampos.setEditableTexto(pnlCmpObligatorios, false, null, true, "");
    ECampos.setEditableTexto(this.pnlOpcional, false, null, true, "");
    this.dcFechaNacimiento.setEnabled(false);
    this.dcFechaRegistro.setEnabled(false);
    this.dcFechaRegistro.setDate(null);
    this.cbSexo.setSelectedIndex(0);
    this.cbTipoCargo.setSelectedIndex(0);
    this.cbSexo.setEnabled(false);
    this.cbTipoCargo.setEnabled(false);    
    this.pnlFoto.setEnabled(false);
    ECampos.buscarBotones(pnlBotones, false, null);
    ECampos.buscarBotones(pnlBotones, true, new Component[]{this.bntCancelar,this.bntGrabar});
    dat = null;
    imagen = null;
    this.pnlImagen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/elaprendiz/resources/defaultlarge.gif")));
    if(cUser.getRegistro() != null)
    {
      setUsuario(cUser.getRegistro());  
    }
    esActualizacion=false; 
}
private void grabarRegistro()
{
     if(cUser.existeDni(this.txtDni.getText())) 
       {
           JOptionPane.showInternalMessageDialog(this, "El DNI: "+txtDni.getText()+
                   " Ya ha sido registrado para otro usuario.", "DNI repetido", JOptionPane.ERROR_MESSAGE);
           return;
       }
       
       if(cUser.existeLogin(this.txtLogn.getText())) 
       {
           JOptionPane.showInternalMessageDialog(this, "El Login: "+txtLogn.getText()+
                   " Ya la tiene otro usuario. \nPorfavor ingrese otro Login.", "Login repetido", JOptionPane.ERROR_MESSAGE);
           return;
       }
       
       if(cUser.existeCodigo(this.txtCodigo.getText())) 
       {
           JOptionPane.showInternalMessageDialog(this, "El Codigo: "+txtCodigo.getText()+
                   " Ya ha sido registrado para otro usuario.", "Codigo repetido", JOptionPane.ERROR_MESSAGE);
           return;
       }
    boolean gr = cUser.guardarRegistro(capturarValoresCampos());
        if(gr)
        {
            JOptionPane.showInternalMessageDialog(this, "Nuevo Usuario registrado corectamente", "Usuario Registrado", JOptionPane.INFORMATION_MESSAGE);
        }
}
private Usuario capturarValoresCampos()
{
    Usuario user = new Usuario();
    user.setDni(this.txtDni.getText());
    user.setCodigo(this.txtCodigo.getText());
    user.setLogin(this.txtLogn.getText());
    user.setNombre(this.txtNombre.getText());
    user.setApellidos(this.txtApellidos.getText());
    if(imagen != null)
    {
        user.setFotoDA(dat);
    }
    user.setClave(String.valueOf(this.txtPassword.getPassword())); 
    user.encriptarPass();
    user.setFono(this.txtFono.getText());
    user.setTipoCargo(this.cbTipoCargo.getSelectedItem().toString());
    user.setSexo(this.cbSexo.getSelectedItem().toString());
    user.setFecRegistro(this.dcFechaRegistro.getDate().getTime());    
    if(dcFechaNacimiento.getCalendar() !=null)
    {
       user.setFechaNacimiento(this.dcFechaNacimiento.getDate().getTime()); 
    }
    user.setFono2(this.txtFono2.getText());
    user.setCelular(this.txtCelular.getText());
    user.setNextel(this.txtNextel.getText());
    user.setEmail(this.txtEmail.getText());
    user.setDescipcion(this.txtADescripcion.getText());
    return user;
}

private Usuario capturarValoresCamposSinFoto()
{
    Usuario user = this.usuario;
    user.setDni(this.txtDni.getText());
    user.setCodigo(this.txtCodigo.getText());
    user.setLogin(this.txtLogn.getText());
    user.setNombre(this.txtNombre.getText());
    user.setApellidos(this.txtApellidos.getText());        
    user.setFono(this.txtFono.getText());
    user.setTipoCargo(this.cbTipoCargo.getSelectedItem().toString());
    user.setSexo(this.cbSexo.getSelectedItem().toString());
    user.setFecRegistro(this.dcFechaRegistro.getDate().getTime());    
    if(dcFechaNacimiento.getCalendar() !=null)
    {
       user.setFechaNacimiento(this.dcFechaNacimiento.getDate().getTime()); 
    }
    user.setFono2(this.txtFono2.getText());
    user.setCelular(this.txtCelular.getText());
    user.setNextel(this.txtNextel.getText());
    user.setEmail(this.txtEmail.getText());
    user.setDescipcion(this.txtADescripcion.getText());
    return user;
}

private Usuario capturarValoresCamposConFoto()
{
    Usuario user = this.usuario;
    user.setDni(this.txtDni.getText());
    user.setCodigo(this.txtCodigo.getText());
    user.setLogin(this.txtLogn.getText());
    user.setNombre(this.txtNombre.getText());
    user.setApellidos(this.txtApellidos.getText());
    if(imagen != null)
    {
        user.setFotoDA(dat);
    }       
    user.setFono(this.txtFono.getText());
    user.setTipoCargo(this.cbTipoCargo.getSelectedItem().toString());
    user.setSexo(this.cbSexo.getSelectedItem().toString());
    user.setFecRegistro(this.dcFechaRegistro.getDate().getTime());    
    if(dcFechaNacimiento.getCalendar() !=null)
    {
       user.setFechaNacimiento(this.dcFechaNacimiento.getDate().getTime()); 
    }
    user.setFono2(this.txtFono2.getText());
    user.setCelular(this.txtCelular.getText());
    user.setNextel(this.txtNextel.getText());
    user.setEmail(this.txtEmail.getText());
    user.setDescipcion(this.txtADescripcion.getText());
    return user;
}
public void mostrarCamposOpcionales(boolean opcion)
{
    if(opcion)
    {
       this.setSize(new Dimension(this.getWidth(),650));
    }else
    {
       this.setSize(new Dimension(this.getWidth(),450)); 
    }
    pnlOpcional.setVisible(opcion); 
}

private void setFiltro()
{
    Helper.setFiltraEntrada(this.txtDni.getDocument(), FiltraEntrada.SOLO_NUMEROS, 30, false);
    Helper.setFiltraEntrada(this.txtCodigo.getDocument(), FiltraEntrada.NUM_LETRAS, 30, false);
    Helper.setFiltraEntrada(this.txtLogn.getDocument(), FiltraEntrada.NUM_LETRAS, 125, false);
    Helper.setFiltraEntrada(this.txtNombre.getDocument(), FiltraEntrada.SOLO_LETRAS, 185, true);
    Helper.setFiltraEntrada(this.txtApellidos.getDocument(), FiltraEntrada.SOLO_LETRAS, 185, true);
    Helper.setFiltraEntrada(this.txtFono.getDocument(), FiltraEntrada.SOLO_NUMEROS, 15, false);
    Helper.setFiltraEntrada(this.txtFono2.getDocument(), FiltraEntrada.SOLO_NUMEROS, 15, false);
    Helper.setFiltraEntrada(this.txtCelular.getDocument(), FiltraEntrada.SOLO_NUMEROS, 15, false);
    
}

private void setUsuario(Usuario  us)
{
    this.txtDni.setText(us.getDni());
    this.txtCodigo.setText(us.getCodigo());
    this.txtNombre.setText(us.getNombre());
    this.txtApellidos.setText(us.getApellidos());
    this.txtLogn.setText(us.getLogin());
    this.txtFono.setText(us.getFono());
    this.cbSexo.setSelectedItem(us.getSexo("sexo"));
    this.cbTipoCargo.setSelectedItem(us.getTipoCargo());
    this.dcFechaRegistro.setDate(new Date(us.getFecRegistro()));
    if(us.getFechaNacimiento()>0)
    {
        this.dcFechaNacimiento.setDate(new Date(us.getFechaNacimiento()));
    }
    this.txtPassword.setText("123456789");
    this.txtFono2.setText(us.getFono2());
    this.txtCelular.setText(us.getCelular());
    this.txtNextel.setText(us.getNextel());
    this.txtEmail.setText(us.getEmail());
    this.txtADescripcion.setText(us.getDescipcion());
    ImageIcon ii = cUser.getFoto(us.getPrimaryKey());
    
    if(ii != null)
    {
        this.pnlImagen.setIcon(ii);
        this.pnlImagen.updateUI();
    }else
    {
        this.pnlImagen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/elaprendiz/resources/defaultlarge.gif")));
        this.pnlImagen.updateUI();
    }
    
    if(us.getActivo() == 1)
    {
        this.bntActivar.setVisible(false);
        bntEliminar.setEnabled(true); 
    }else
    {
        this.bntActivar.setVisible(true);
        bntEliminar.setEnabled(false); 
    }
    DefaultMutableTreeNode permisos = us.getPermisos();
    tPermisos.setModel(new javax.swing.tree.DefaultTreeModel(permisos));
    tPermisos.setExpandsSelectedPaths(true);
    tPermisos.setShowsRootHandles(true);     
    expandirNodos(tPermisos);   
}

private void expandirNodos(JTree arbol)
{
    if(arbol.getRowCount()==1)
        return;         
   
    for (int i = 0; i<arbol.getRowCount();i++) {
         arbol.expandRow(i);
         arbol.setSelectionRow(i);
         arbol.setExpandsSelectedPaths(true);
    }    
}
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bntActivar;
    private elaprendiz.gui.button.ButtonRect bntAnterior;
    private elaprendiz.gui.button.ButtonRect bntBitacora;
    private elaprendiz.gui.button.ButtonRect bntBuscar;
    private elaprendiz.gui.button.ButtonRect bntCancelar;
    private elaprendiz.gui.button.ButtonRect bntEliminar;
    private elaprendiz.gui.button.ButtonRect bntGrabar;
    private elaprendiz.gui.button.ButtonRect bntModificar;
    private elaprendiz.gui.button.ButtonRect bntNuevo;
    private elaprendiz.gui.button.ButtonRect bntPass;
    private elaprendiz.gui.button.ButtonRect bntPrimero;
    private elaprendiz.gui.button.ButtonRect bntSalir;
    private elaprendiz.gui.button.ButtonRect bntSiguiente;
    private elaprendiz.gui.button.ButtonRect bntUltimo;
    private elaprendiz.gui.comboBox.ComboBoxRect cbSexo;
    private elaprendiz.gui.comboBox.ComboBoxRect cbTipoCargo;
    private com.toedter.calendar.JDateChooser dcFechaNacimiento;
    private com.toedter.calendar.JDateChooser dcFechaRegistro;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private elaprendiz.gui.panel.PanelImage panelImage1;
    private javax.swing.JPanel pnlBotones;
    private javax.swing.JPanel pnlCmpObligatorios;
    private javax.swing.JPanel pnlFoto;
    private elaprendiz.gui.panel.PanelImage pnlImagen;
    private javax.swing.JPanel pnlOpcional;
    private javax.swing.JPanel pnlPaginador;
    private javax.swing.JTree tPermisos;
    private javax.swing.JToggleButton tbntOpcional;
    private javax.swing.JTextArea txtADescripcion;
    private elaprendiz.gui.textField.TextFieldRectBackground txtApellidos;
    private elaprendiz.gui.textField.TextField txtCelular;
    private elaprendiz.gui.textField.TextFieldRectBackground txtCodigo;
    private elaprendiz.gui.textField.TextFieldRectBackground txtDni;
    private elaprendiz.gui.textField.TextField txtEmail;
    private elaprendiz.gui.textField.TextFieldRectBackground txtFono;
    private elaprendiz.gui.textField.TextField txtFono2;
    private elaprendiz.gui.textField.TextFieldRectBackground txtLogn;
    private elaprendiz.gui.textField.TextField txtNextel;
    private elaprendiz.gui.textField.TextFieldRectBackground txtNombre;
    private elaprendiz.gui.passwordField.PasswordFieldRectBackground txtPassword;
    // End of variables declaration//GEN-END:variables
}
